<!doctype html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>后台登录</title>
        <link rel="stylesheet" href="../css/font.css">
        <link rel="stylesheet" href="../css/login.css">
        <link rel="stylesheet" href="../css/xadmin.css">
        <script src="../js/vue2.7min.js"></script>
        <script src="../js/axios.min.js"></script>
    </head>
    <body class="login-bg">

        <div class="login layui-anim layui-anim-up">
            <div class="message">提瓦特物流仓库管理系统</div>
            <form method="post" action="red/login" class="layui-form" id="app">
                <input name="userName" lay-verify="required" placeholder="用户名" type="text" class="layui-input"
                       v-model="name">
                <hr class="hr15">
                <input name="password" lay-verify="required" placeholder="密码  " type="password" class="layui-input"
                       v-model="password">
                <hr class="hr15">
                <input value="登录" lay-submit lay-filter="login" style="width:100%;" type="button" @click="toLogin">
                <hr class="hr20">
                <div class="layui-input" v-model="msg">{{msg}}</div>
            </form>
        </div>


        <script type="text/javascript">
            var vm = new Vue({
                el: "#app",
                data: {
                    name: "admin",
                    password: 123456,
                    msg: null
                },
                methods: {
                    toLogin: function () {
                        //开始ajax
                        var myJson = {
                            name: this.name,
                            password: this.password
                        }
                        axios.post("../../red/login", myJson)
                            .then(function (response) {
                                console.log(response);
                                vm.msg = response.data.msg;
                                //判断是否登录
                                if (response.data.code === 1) {
                                    //页面跳转
                                    window.location.href = 'index/index.html';
                                } else {
                                    vm.msg
                                }
                            }, function (err) {
                                console.log(err);
                            })
                    },
                    //获取url参数
                    url1: function (name) {
                        //获取上一地址中的get参数
                        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                        var r = window.location.search.substr(1).match(reg);
                        if (r != null)
                            return unescape(r[2]);
                        return null;
                    }
                }, mounted: function () {
                    // console.log("获取cookie");
                    // console.log("cookie="+document.cookie);
                    console.log("开始判断是不是登出的信息");
                    var readMsg = this.url1("msg");
                    if (readMsg != null && readMsg != "") {
                        this.msg = "账号登出成功";
                    }
                }
            });
        </script>
        <!-- 底部结束 -->
    </body>
</html>